package com.ruoyi.web.controller.dormitory;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dormitory.domain.TbDormitoryMember;
import com.ruoyi.dormitory.service.ITbDormitoryMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宿舍成员Controller
 *
 * @author ruoyi
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/dormitory/member")
public class TbDormitoryMemberController extends BaseController
{
    @Autowired
    private ITbDormitoryMemberService tbDormitoryMemberService;

    /**
     * 查询宿舍成员列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDormitoryMember tbDormitoryMember)
    {
        startPage();
        List<TbDormitoryMember> list = tbDormitoryMemberService.selectTbDormitoryMemberList(tbDormitoryMember);
        return getDataTable(list);
    }

    /**
     * 导出宿舍成员列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:member:export')")
    @Log(title = "宿舍成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDormitoryMember tbDormitoryMember)
    {
        List<TbDormitoryMember> list = tbDormitoryMemberService.selectTbDormitoryMemberList(tbDormitoryMember);
        ExcelUtil<TbDormitoryMember> util = new ExcelUtil<TbDormitoryMember>(TbDormitoryMember.class);
        util.exportExcel(response, list, "宿舍成员数据");
    }

    /**
     * 获取宿舍成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('dormitory:member:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbDormitoryMemberService.selectTbDormitoryMemberById(id));
    }

    /**
     * 新增宿舍成员
     */
    @PreAuthorize("@ss.hasPermi('dormitory:member:add')")
    @Log(title = "宿舍成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDormitoryMember tbDormitoryMember)
    {
        return toAjax(tbDormitoryMemberService.insertTbDormitoryMember(tbDormitoryMember));
    }

    /**
     * 修改宿舍成员
     */
    @PreAuthorize("@ss.hasPermi('dormitory:member:edit')")
    @Log(title = "宿舍成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDormitoryMember tbDormitoryMember)
    {
        return toAjax(tbDormitoryMemberService.updateTbDormitoryMember(tbDormitoryMember));
    }

    /**
     * 删除宿舍成员
     */
    @PreAuthorize("@ss.hasPermi('dormitory:member:remove')")
    @Log(title = "宿舍成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbDormitoryMemberService.deleteTbDormitoryMemberByIds(ids));
    }
}
